4D Server v12On Server Open Connection Database Method |
||||||||||
|
4D Server v12
On Server Open Connection Database Method
|
Parameter | Description |
$1 | User ID number used internally by 4D Server to identify users |
$2 | Connection ID number used internally by 4D Server to identify a connection |
$3 | Obsolete: Always returns 0 but must be declared |
These ID numbers are not directly usable as sources of information to be passed as, for example, parameters to a 4D command. However, they provide a way to uniquely identify a 4D Client process between the On Server Open Connection Database Method and the On Server Close Connection Database Method. At any moment of a 4D Server session, the combination of these values is unique. By storing this information in an interprocess array or a table, the two database methods can exchange information. In the example at the end of this section, the two database methods use this information to store the date and time of the beginning and end of a connection in the same record of a table.
The following example shows how to maintain a log of the connections to the database using the On Server Open Connection Database Method and the On Server Close Connection Database Method. The [Server Log] table (shown below) is used to keep track of the connection processes:
The information stored in this table is managed by the On Server Open Connection Database Method and the On Server Close Connection Database Method listed here:
` On Server Open Connection Database Method
C_LONGINT($0;$1;$2;$3)
` Create a [Server Log] record
CREATE RECORD([Server Log])
[Server Log]Log ID:=Sequence number([Server Log])
` Save the Log Date and Time
[Server Log]Log Date:=Current date
[Server Log]Log Time:=Current time
` Save the connection information
[Server Log]User ID:=$1
[Server Log]Connection ID:=$2
SAVE RECORD([Server Log])
` Returns no error so that the connection can continue
$0:=0
` On Server Close Connection Database Method
C_LONGINT($1;$2;$3)
` Retrieve the [Server Log] record
QUERY([Server Log];[Server Log]User ID=$1;*)
QUERY([Server Log]; & ;[Server Log]Connection ID=$2;*)
QUERY([Server Log]; & ;[Server Log]Process ID=0)
` Save the Exit date and time
[Server Log]Exit Date:=Current date
[Server Log]Exit Time:=Current time
` Save the process information
[Server Log]Process ID:=Current process
PROCESS PROPERTIES([Server Log]Process ID;$vsProcName;$vlProcState;$vlProcTime)
[Server Log]Process Name:=$vsProcName
SAVE RECORD([Server Log])
Here are some entries in the [Server Log] showing several remote connections:
The following example prevents any new connection from 2 to 4 A.M.
` On Server Open Connection Database Method
C_LONGINT($0;$1;$2;$3)
If((?02:00:00?<=Current time)&(Current time<?04:00:00?))
$0:=22000
Else
$0:=0
End if
Product: 4D Server
Theme: 4D Server Database Methods
On Server Close Connection Database Method